#include "ttMsgMap.h"

ttMsgMap::ttMsgMap() : m_defFunc(NULL)
{}

ttMsgMap::~ttMsgMap()
{
	for (TTLIST::iterator iter = m_MsgMap.begin(); iter != m_MsgMap.end(); ++ iter){
		if (NULL != (*iter)){
			delete *iter;
		}
	}
}

int 
ttMsgMap::push_front(IttFunc *pFunc)
{
	m_MsgMap.push_front(pFunc);
	return 0;
}

int 
ttMsgMap::run(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	for (TTLIST::iterator iter = m_MsgMap.begin(); iter != m_MsgMap.end(); ++ iter){
		if (NULL != (*iter)){
			int ret = (*iter)->runShell(hwnd, message, wParam, lParam);
			if (0 == ret){
				return ret;			
			}
			else if (1 == ret){
				return callDefFunc(hwnd, message, wParam, lParam);
			}
		}
	}
	return callDefFunc(hwnd, message, wParam, lParam);
}

int 
ttMsgMap::setDefFunc(IttFunc *pdef)
{
	m_defFunc = pdef;
	return 0;
}

int 
ttMsgMap::callDefFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (NULL != this->m_defFunc){
		return this->m_defFunc->runShell(hwnd, message, wParam, lParam);
	}
	return 0;
}